package com.test.flink_source.source;

import org.apache.flink.streaming.api.functions.source.SourceFunction;

import java.util.UUID;
import java.util.concurrent.TimeUnit;

/**
 * 自定义source
 *
 * 1. 实现接口
 * 2. 重写方法
 */
public class MySource implements SourceFunction<String> {

    private boolean flag = true;

    @Override
    public void run(SourceContext<String> ctx) throws Exception {
        while (flag) {
            String res = UUID.randomUUID().toString().replace("-", "");
            ctx.collect(res);

            TimeUnit.SECONDS.sleep(2);
        }
    }

    @Override
    public void cancel() {
        flag = false;
    }
}
